package _cn.com.jsr.translation.termidentifier.identifier;

import cn.com.jsr.translation.termidentifier.Dictionary;
import cn.com.jsr.translation.termidentifier.Seeker;
import cn.com.jsr.translation.termidentifier.identifier.Translate;
import junit.framework.TestCase;

public class _Quote extends TestCase{
	/**
	 * 测试目标：确保正文中出现的术语只有在字典中存在定义时才会被翻译
	 */
	public void test1(){
		String src = "term1 term2 term3 term1 sentense term1 term12";
		
		Dictionary dict = new Dictionary();
		dict.set("term1", "术语1");
		
		Translate translate = new Translate();
		translate.setDictionary(dict);
		String tar = translate.seek(src);
		
		assertEquals(tar, "术语1 term2 term3 术语1 sentense 术语1 term12");
	}
	
	/**
	 * 测试目标：确保无论字典中定义的术语是否存在包含（即，一个术语词组中包含了另一个术语单词）情况，原文都能被正确翻译
	 */
	public void test2(){
		String src = "term1 term2 term1 term12 term sen term   translation term term translation";
		
		Dictionary dict = new Dictionary();
		dict.set("term", "术语");
		dict.set("term1", "术语1");
		dict.set("term translation", "术语翻译");
		
		Translate translate = new Translate();
		translate.setDictionary(dict);
		String tar = translate.seek(src, Seeker.MERGE_BLANK);
		
		assertEquals(tar, "术语1 term2 术语1 term12 术语 sen 术语翻译 术语 术语翻译");
	}
	
	/**
	 * 测试目标：确保字典定义的术语大小写与正文中术语大小写是否一致，以及查找策略是否区分大小写能够正确影响术语的识别
	 */
	public void test3(){
		String src = "term terms TERM TERMS";
		
		Dictionary dict = new Dictionary();
		dict.set("term", "术语");
		
		Translate translate = new Translate();
		translate.setDictionary(dict);
		String tar = translate.seek(src);
		
		assertEquals(tar, "术语 terms TERM TERMS");
		tar = translate.seek(src, Seeker.CASE_INSENSITIVE);
		assertEquals(tar, "术语 terms 术语 TERMS");
		
		dict.remove("term");
		dict.set("TERM", "术语");
		tar = translate.seek(src);
		assertEquals(tar, "term terms 术语 TERMS");
		tar = translate.seek(src, Seeker.CASE_INSENSITIVE);
		assertEquals(tar, "术语 terms 术语 TERMS");
	}
	
	/**
	 * 测试目标：确保字典定义的术语中单词之间的空白与正文中的术语是否一致，以及查找策略是否忽略多个空白是否正确影响术语的识别
	 */
	public void test4(){
		String src = " term terms term translation   term term   translation  term \r\n translation";

		Dictionary dict = new Dictionary();
		dict.set("term translation", "术语翻译");
		
		Translate translate = new Translate();
		translate.setDictionary(dict);
		String tar = translate.seek(src);
		
		assertEquals(tar, " term terms 术语翻译   term term   translation  term \r\n translation");
		tar = translate.seek(src, Seeker.MERGE_BLANK);
		assertEquals(tar, " term terms 术语翻译   term 术语翻译  术语翻译");
	}
	
	/**
	 * 测试目标：确保对于字典中定义的术语，无论其在正文中出现次数多少和出现位置，程序都能够正确地识别所有术语
	 */
	public void test5(){
		String src = " term alsd term termska sdfakterm term term ! #term! 23term32s";

		Dictionary dict = new Dictionary();
		dict.set("term", "术语");
		
		Translate translate = new Translate();
		translate.setDictionary(dict);
		String tar = translate.seek(src);
		
		assertEquals(tar, " 术语 alsd 术语 termska sdfakterm 术语 术语 ! #术语! 23term32s");
	}
	
	/**
	 * 测试目标：确保对于字典中定义的术语，无论其是否出现在正文的多行与否，抑或被拆分成多行，程序都能够正确地识别所有术语
	 */
	public void test6(){
		String src = " term translation   term term \r\n translation term \r TRANSLATION. term \n translation  \n\n\r\r\n term translation";

		Dictionary dict = new Dictionary();
		dict.set("term translation", "术语译文");
		
		Translate translate = new Translate();
		translate.setDictionary(dict);
		String tar = translate.seek(src, Seeker.MERGE_BLANK | Seeker.CASE_INSENSITIVE);
		
		assertEquals(tar, " 术语译文   term 术语译文 术语译文. 术语译文  \n\n\r\r\n 术语译文");
	}
}
